package com.hp.attendance.serlvet.employee;

import com.hp.attendance.entity.EmpRole;
import com.hp.attendance.service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/addDistriRole")
public class RoleAddDisTirServlet extends HttpServlet {

    private EmployeeService employeeService = new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分配角色
        //获取员工id
        String empId = req.getParameter("empId");
        //获取选择的角色id
        String[] roleIds = req.getParameterValues("rolecheck");
        ArrayList<EmpRole> list = new ArrayList<EmpRole>();
        for (String roleId : roleIds) {
            EmpRole er = new EmpRole();
            er.setEmp_id(Integer.parseInt(empId));
            er.setR_id(Integer.parseInt(roleId));
            list.add(er);
        }
        employeeService.dittriRole(list,Integer.parseInt(empId));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
